package com.oe.service.impl;


import com.alibaba.fastjson.JSON;
import com.google.gson.JsonObject;
import com.oe.context.UserContext;
import com.oe.context.UserInfo;
import com.oe.service.LdmService;
import org.apache.dubbo.rpc.RpcContext;

import java.util.Random;

public class LdmServiceImpl implements LdmService {

    public String returnClientIp() {
        UserInfo ret = JSON.parseObject(RpcContext.getContext().getAttachment(UserContext.USER_KEY),UserInfo.class);
        System.out.println("=======客户端IP："+ret.getAccessIp());
        return ret.getAccessIp();
    }

    @Override
    public String methodB() {
        Random random = new Random();
        int i = random.nextInt(1000);
        try {
            Thread.sleep(i);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return "methodB";
    }

    @Override
    public String methodC() {
        Random random = new Random();
        int i = random.nextInt(1000);
        try {
            Thread.sleep(i);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return "methodC";
    }

    @Override
    public String methodD() {
        Random random = new Random();
        int i = random.nextInt(1000);
        try {
            Thread.sleep(i);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return "methodD";
    }
}
